package com.example.test.conview.view.core;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Typeface;
import android.text.TextUtils;

import com.puty.conputyutils.MultiLanguageUtils;
import com.puty.conputyutils.SharedPreferencesHelperUtils;
import com.puty.conputyutils.StringUtils;
import com.puty.conputyutils.common.PutyUtilsConst;
import com.puty.conputyview.R;
import com.puty.conputyview.common.PutyConst;
import com.puty.conputyview.view.tool.Global;

import java.util.UUID;

/**
 *    元素类
 */
public abstract class BaseElement extends Property implements Cloneable{
    public String entityId = UUID.randomUUID().toString();
    public Label lb;
    /**
     * 是否是阿拉伯语
     */
    public boolean isArab = false;
    /**
     * 图片压缩比例（用来优化内存的）
     */
    public float compressionRatio = 1;//图片压缩比例（用来优化内存的）
    /**
     * 内容输入模式 0 手工 1 excel数据
     */
    public int inputMode = 0;
    /**
     * 递变数据 增长步长
     */
    public int ddStep = 0;
    /**
     * 显示内容
     */
    public Context mContext;// 显示内容
    /**
     * 字体
     */
    public String familyName = "";//字体

    /**
     * 字体类型
     */
    public Typeface typeface;
    /**
     * 字体粗细 一维码 。文本
     */
    public int fontBlod = 0;// 字体粗细 一维码 。文本
    /**
     * 斜体 一维码 。文本
     */
    public int fontItalic = 0;// 斜体 一维码 。文本
    /**
     * 下划线 一维码 。文本
     */
    public int fontUnderline = 0;// 下划线 一维码 。文本
    /**
     * 删除线
     */
    public int fontDelete = 0;//删除线
    /**
     *  //小四(10) -> 二号(6)
     */
    public int fontIndex = 7;  //小四(10) -> 二号(6)
    /**
     * //80.0f; 字体大小
     */
    public float fontSize = Global.fontSize[this.fontIndex] * 8;//80.0f; 字体大小
    /**
     * //字间距
     */
    public float textCellSpace = 0;
    /**
     *  //日期偏移量（以前用的   这个可能是日期偏移）
     */
    public String timedeviation = "0";
    /**
     * //日期偏移量（后面加的   功能没有实现）
     */
    public String datedeviation = "0";
    /**
     * 缩放
     */
    public float scale = 1.0f;
    /**
     * 元素类型
     */
    public int type = -1;// 元素类型
    // public RectF rect = new RectF();
    /**
     * 缩放方向 x轴方向0   y轴方向1  右下角方向2
     */
    public int zoomdirect = 0;// 缩放方向 x轴方向0   y轴方向1  右下角方向2
    /**
     * 是否移动
     */
    public boolean ismoving = false;
    /**
     * 是否被选中
     */
    public boolean isselected = false;//是否被选中
    /**
     * 标记是否是最后一个被选中的
     */
    public boolean isLastSelected = false;//标记是否是最后一个被选中的
    public boolean isclicked = false;
    /**
     * 当前放大缩小
     */
    public boolean iszoom = false;// 当前放大缩小
    /**
     * 是否显示
     */
    public boolean isShow =true;
    /**
     * 内容
     */
    public String content = "";
    /**
     * 元素左侧距离
     */
    public float left;//元素左侧距离
    /**
     * 元素顶部距离
     */
    public float top;//元素顶部距离
    /**
     * 元素宽
     */
    public float width = 10;//元素宽
    /**
     * 元素高
     */
    public float height = 10;//元素高
    public boolean backselected = false;
    /**
     *  // 旋转 0，90，180，270
     */
    public int rate = 0;
    /**
     *  // 排列方式，0 横排， 1 竖排
     */
    public int orientation;
    public boolean isNew = false;
    /**
     * // 0 不锁定 1锁定
     */
    public int isLock = 0;
    /**
     * //rfid开关
     */
    public int rfidisLock = 0;
    /**
     * // 0 不是打印对象 1打印
     */
    public int isPrinter = 1;
    /**
     * //是否反白
     */
    public boolean isAntiWhite = false;//是否反白
    /**
     * 镜像
     */
    public boolean isMirror = false;// 镜像
    /**
     * 文字反白
     */
    public boolean foreground = false;//文字反白
    /**
     * 对齐模式 0 居左 1 居中 2 居右 3拉伸
     */
    public int textMode = PutyUtilsConst.ALIGNMENT_MODE_STRETCH;
    /**
     * 行间距
     */
    public float textRowSpace = 0;
    /**
     * //编码规范
     */
    public int bformat = 3;
    /**
     * 条码位置 1、条码在上方， 2、条码下方
     */
    public int textPlace = 2;
    /**
     * //是否显示logo
     */
    public boolean isShowLogo = false;//是否显示logo
    /***
     * 黑白显示
     * */
    public int isblack = 0;
    /**
     * 图片的灰度阈值
     */
    public int grayYZ = 127;

    /**
     * 原始图
     */
    public Bitmap tempBitmap;
    /**
     * 原始图片路径
     */
    public String imageUrlString = "";


    /**
     * //日期格式选择项
     */
    public int date_format = 7, time_format = 2;

    public BaseElement(Context context, Label lb) {
        if (context == null||lb == null) return;
        this.mContext = context;
        this.lb = lb;
        //使用了默认字体
        String fname = (String) SharedPreferencesHelperUtils.getSharedPreference(PutyConst
                .FONT_USED_NAME, "");
        if(TextUtils.isEmpty(fname)){
           fname =  context.getString(R.string.default_font);
        }
        this.familyName = fname;//AppUtil.fontName;
        //this.typeface = AppUtil.globalFont;

        this.isArab = MultiLanguageUtils.isRTL(context);
    }

    public void setFontSize() {

    }

    public void draw(Canvas canvas){
    }
    public void draw(Canvas canvas,boolean isPrinting){
    }
    /**
     * 缩放
     */
    public void zoom(float x, float y, float width, float height) {

    }

    public void zoomOtherSelected(float x, float y) {
        float minSize = lb.scale * 8;
        if (lb.isMunSelect == 1) {
            //多选状态下
            for (int i = 0; i < lb.Elements.size(); i++) {
                BaseElement element = lb.Elements.get(i);
                if (element.isselected) {
                    //往X方向
                    element.zoomdirect = this.zoomdirect;
                    if (element instanceof TableElement) {
                        TableElement tableel = (TableElement) element;
                        //往X方向
                        if (this.zoomdirect == 0) {
                            float temporaryWidth = tableel.width;
                            tableel.width += x;
                            if (tableel.width <= minSize * tableel.cellcount) {
                                tableel.width = minSize * tableel.cellcount;
                            }
                            for (int j = 0; j < tableel.columWidths.size(); j++) {
                                Float aFloat = tableel.columWidths.get(j);
                                aFloat = aFloat / temporaryWidth * tableel.width;
                                aFloat = aFloat < minSize ? minSize : aFloat;
                                tableel.columWidths.set(j, aFloat);
                                if (tableel.mZoomWChangedListener != null) {
                                    tableel.mZoomWChangedListener.zoomColumW(j, aFloat);
                                }
                            }
                        } else {
                            float temporaryHeight = tableel.height;
                            tableel.height += y;
                            if (tableel.height <= minSize * tableel.rowcount) {
                                tableel.height = minSize * tableel.rowcount;
                            }
                            //等比例放大/缩小每行高度
                            for (int j = 0; j < tableel.rowHeights.size(); j++) {
                                Float aFloat = tableel.rowHeights.get(j);
                                aFloat = aFloat / temporaryHeight * tableel.height;
                                aFloat = aFloat < minSize ? minSize : aFloat;
                                tableel.rowHeights.set(j, aFloat);
                                if (tableel.mZoomHChangedListener != null) {
                                    tableel.mZoomHChangedListener.zoomRowH(j, aFloat);
                                }
                            }
                        }
                    }else if (element instanceof TextElement) {
                        TextElement txtel = (TextElement) element;
                        switch (txtel.rate) {
                            case PutyConst.RATE_0:
                                txtel.width += x;
                                if (txtel.width <= PutyConst.RATE_BOUNDARY) {
                                    txtel.width = PutyConst.RATE_BOUNDARY;
                                }
                                break;
                            case PutyConst.RATE_180:
                                txtel.width -= x;
                                txtel.left += x;
                                if (txtel.width <= PutyConst.RATE_BOUNDARY) {
                                    txtel.width = PutyConst.RATE_BOUNDARY;
                                }
                                break;
                            case PutyConst.RATE_90:
                                txtel.height += y;
                                if (txtel.height <= PutyConst.RATE_BOUNDARY) {
                                    txtel.height = PutyConst.RATE_BOUNDARY;
                                }
                                break;
                            case PutyConst.RATE_270:
                                txtel.height -= y;
                                txtel.top += y;
                                if (txtel.height <= PutyConst.RATE_BOUNDARY) {
                                    txtel.height = PutyConst.RATE_BOUNDARY;
                                }
                                break;
                        }
                        //重新初始化
                        txtel.rate(this.rate);
                        txtel.initBitmap();
                    } else if (element instanceof QrCodeElement) {
                        QrCodeElement qrCodeElement = (QrCodeElement) element;
                        qrCodeElement.width += x;
                        qrCodeElement.height += x;
                        if (qrCodeElement.width <= PutyConst.RATE_BOUNDARY) {
                            qrCodeElement.width = PutyConst.RATE_BOUNDARY;
                        }
                        if (qrCodeElement.height <= PutyConst.RATE_BOUNDARY) {
                            qrCodeElement.height = PutyConst.RATE_BOUNDARY;
                        }
                    }else {
                        if (element.zoomdirect == 0) {
                            element.width += x;
                            if (element.width <= 50) {
                                element.width = 50;
                            }
                        } else {
                            element.height += y;
                            if (element.height <= 50) {
                                element.height = 50;
                            }
                        }
                    }
                    element.init();
                }
            }
        }
    }

    /**
     * 旋转
     */
    public void rate(int degree) {
    }


    public void init() {
    }

    /**
     * 旋转处理
     *
     * @param degree 旋转角度
     */
    protected void rotation(int degree) {
        //缓存
        int tempDegree = degree;

        //旋转的角度
        degree = Math.abs(degree - this.rate);
        switch (degree) {
            case PutyConst.RATE_0:
            case PutyConst.RATE_180:
                break;
            case PutyConst.RATE_90:
            case PutyConst.RATE_270:
                PointF center = new PointF(left + this.width / 2, top + this.height / 2);
                float temp = this.width;
                this.width = this.height;
                this.height = temp;
                this.left = center.x - this.width / 2;
                this.top = center.y - this.height / 2;
                break;
        }
        this.rate = tempDegree;
    }

    //拉伸
    protected void textalignPP(float left, float top,
                               float textHeight, String content,
                               Paint textPaint, Canvas canvas, float space) {
        textalignPP(left, top, textHeight, content, textPaint, canvas, space, false,false);
    }

    //拉伸
    protected void textalignPP(float left, float top,
                               float textHeight, String content,
                               Paint textPaint, Canvas canvas, float space, boolean isAntiWhite,boolean foreground) {
        char[] arr = content.toCharArray();
        int len = arr.length;
        if (len > 1) {
            float w = this.width / compressionRatio;
            float h = this.height / compressionRatio;
            if (rate == 90 || rate == 270) {
                w = this.height / compressionRatio;
                h = this.width / compressionRatio;
            }
            if (isAntiWhite) {
                textPaint.setColor(Color.WHITE);
                Paint p = new Paint();
                p.setColor(Color.BLACK);// 设置灰色
                p.setStyle(Paint.Style.FILL);//设置填满
                canvas.drawRect(left, top, left + w, top + h, p);// 矩形
            } else  if (foreground){
                textPaint.setColor(Color.WHITE);
            }else{
                textPaint.setColor(Color.BLACK);
            }
            if ((MultiLanguageUtils.isRTL(mContext) || StringUtils.textContainsKhmer(content)) && type == 1) {
                canvas.drawText(content, left, top + textHeight - textHeight / 5, textPaint);
            } else {
                for (int i = 0; i < len; i++) {
                    String vString = String.valueOf(arr[i]);
                    //单个字体宽度
                    float textWidth = getContentWhidth(textPaint, vString);
                    canvas.drawText(vString, left, top + textHeight - textHeight / 5, textPaint);
                    left += textWidth + textCellSpace*8*lb.scale + space;
                }
            }
        } else {
            canvas.drawText(content, left, top + textHeight - textHeight / 5, textPaint);
        }

    }

    //居右对齐
    protected void textalignRight(float left, float top, float textHeight, String content,
                                  Paint textPaint, Canvas canvas) {
        textalignRight(left, top, textHeight, content, textPaint, canvas, false,false);
    }

    //居右对齐
    protected void textalignRight(float left, float top, float textHeight, String content, Paint textPaint, Canvas canvas, boolean isAntiWhite,boolean foreground) {
        char[] arr = content.toCharArray();
        //获取总的长度
        float total = getContentWhidth(textPaint, content);
        float w = this.width / compressionRatio;
        float h = this.height / compressionRatio;
        if (rate == 90 || rate == 270) {
            w = this.height / compressionRatio;
            h = this.width / compressionRatio;
        }
        if (isAntiWhite) {
            textPaint.setColor(Color.WHITE);
            Paint p = new Paint();
            p.setColor(Color.BLACK);// 设置灰色
            p.setStyle(Paint.Style.FILL);//设置填满
            canvas.drawRect(left, top, left + w, top + h, p);// 矩形
        } else if (foreground){
            textPaint.setColor(Color.WHITE);
        }else{
            textPaint.setColor(Color.BLACK);
        }


        left += w - total - textCellSpace*8*lb.scale * (arr.length - 1);//获取偏移量 总宽度-字符串宽度
        if ((isArab || StringUtils.textContainsKhmer(content)) && type == 1) {
            canvas.drawText(content, left, top + textHeight - textHeight / 5, textPaint);
        } else {
            for (int i = 0; i < arr.length; i++) {
                String vString = String.valueOf(arr[i]);
                //单个字体宽度
                float textWidth = getContentWhidth(textPaint, vString);
                canvas.drawText(vString, left, top + textHeight - textHeight / 5, textPaint);
                left += textWidth + textCellSpace*8*lb.scale;
            }
        }
    }


    protected void textalignCenter(float left, float top, float textHeight, String content, Paint
            textPaint, Canvas canvas) {
        textalignCenter(left, top, textHeight, content, textPaint, canvas, false,false);
    }

    //居中对齐
    protected void textalignCenter(float left, float top, float textHeight, String content, Paint textPaint, Canvas canvas, boolean isAntiWhite,boolean foreground) {
        float w = this.width / compressionRatio;
        float h = this.height / compressionRatio;
        if (rate == 90 || rate == 270) {
            w = this.height / compressionRatio;
            h = this.width / compressionRatio;
        }
        if (isAntiWhite) {
            textPaint.setColor(Color.WHITE);
            Paint p = new Paint();
            p.setColor(Color.BLACK);// 设置灰色
            p.setStyle(Paint.Style.FILL);//设置填满
            canvas.drawRect(left, top, left + w, top + h, p);// 矩形
        } else  if (foreground){
            textPaint.setColor(Color.WHITE);
        }else{
            textPaint.setColor(Color.BLACK);
        }

        char[] arr = content.toCharArray();
        int len = arr.length;
        //获取总的长度
        float total = getContentWhidth(textPaint, content);
        left += (w - total - textCellSpace*8*lb.scale * (len - 1)) / 2;//获取偏移量 总宽度-字符串宽度 /2

        if ((MultiLanguageUtils.isRTL(mContext) || StringUtils.textContainsKhmer(content))&& type == 1) {
            canvas.drawText(content, left, top + textHeight - textHeight / 5, textPaint);
        } else {
            for (int i = 0; i < len; i++) {
                String vString = String.valueOf(arr[i]);
                float textWidth = 0;
                //单个字体宽度
                textWidth = getContentWhidth(textPaint, vString);
                canvas.drawText(vString, left, top + textHeight - textHeight / 5, textPaint);
                left += textWidth + textCellSpace*8*lb.scale;
            }
        }


    }



    //EAN_13条码上
    protected void textalignEan_13Center(float left, float top, float textHeight, String content, Paint
            textPaint, Canvas canvas) {
        char[] arr = content.toCharArray();

        //获取总的长度
        float txWidth = getContentWhidth(textPaint, "5");//文字的宽度

        float w;// = this.width;
        float right_q = 0;//= (w+txWidth)/2-w/50;
        float left_q = 0;//= left+txWidth+w/30;
        float textW = 0;//= txWidth*6;

        float spaceq = 0;//前面字符空隙 总宽度-字符串宽度
        float right_h = 0;//= w-(w+txWidth)/30;
        float left_h = 0;//= (w+txWidth)/2+(w+txWidth)/50;
        float spaceh = 0;//后面字符空隙 总宽度-字符串宽度
        if (rate == 90 || rate == 270) {
            w = this.height / compressionRatio;
            right_q = (w + txWidth) / 2 - w / 50;
            left_q = left + txWidth + w / 30;
            textW = txWidth * 6;

            right_h = w - (w + txWidth) / 30;
            left_h = (w + txWidth) / 2 + (w + txWidth) / 50;
        } else {
            //获取总的长度
            w = this.width / compressionRatio;
            right_q = (w + txWidth) / 2 - w / 50;
            left_q = left + txWidth + w / 30;
            textW = txWidth * 6;
            right_h = w - (w + txWidth) / 30;
            left_h = (w + txWidth) / 2 + (w + txWidth) / 50;
        }
        Paint p = new Paint();
        p.setColor(Color.WHITE);
        canvas.drawRect(left_q, top + textHeight / 2, right_q, top - textHeight / 2, p);
        canvas.drawRect(left_h, top + textHeight / 2, right_h, top - textHeight / 2, p);
        for (int i = 0; i < 1; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left, top + textHeight / 5,
                    textPaint);
        }
        spaceq = (right_q - left_q - textW) / 5;
        for (int i = 1; i < 7; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_q, top + textHeight / 5,
                    textPaint);
            left_q += txWidth + spaceq;
        }
        spaceh = (right_h - left_h - textW) / 5;
        for (int i = 7; i < 13; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_h, top + textHeight / 5,
                    textPaint);
            left_h += txWidth + spaceh;
        }
    }

    //EAN_13条码下方
    protected void textalignEan_13CenterXia(float left, float top, float textHeight, String content, Paint
            textPaint, Canvas canvas) {
        char[] arr = content.toCharArray();

        //获取总的长度
        float txWidth = getContentWhidth(textPaint, "5");//文字的宽度
        float w = this.width / compressionRatio;
        float right_q;//= (w+txWidth)/2-w/50;
        float left_q;//= left+txWidth+w/30;
        float textW;//= txWidth*6;

        float spaceq = 0;//前面字符空隙 总宽度-字符串宽度
        float right_h;//= w-(w+txWidth)/30;
        float left_h;//= (w+txWidth)/2+(w+txWidth)/50;
        float spaceh = 0;//后面字符空隙 总宽度-字符串宽度
        if (rate == 90 || rate == 270) {
            w = this.height;
            right_q = (w + txWidth) / 2 - w / 50;
            left_q = left + txWidth + w / 30;
            textW = txWidth * 6;
            right_h = w - (w + txWidth) / 30;
            left_h = (w + txWidth) / 2 + (w + txWidth) / 50;

        } else {
            right_q = (w + txWidth) / 2 - w / 50;
            left_q = left + txWidth + w / 30;
            textW = txWidth * 6;
            right_h = w - (w + txWidth) / 30;
            left_h = (w + txWidth) / 2 + (w + txWidth) / 50;


        }
        Paint p = new Paint();
        p.setColor(Color.WHITE);
        canvas.drawRect(left_q, textHeight / 2, right_q, textHeight * 3 / 2, p);
        canvas.drawRect(left_h, textHeight / 2, right_h, textHeight * 3 / 2, p);
        for (int i = 0; i < 1; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left, textHeight + textHeight / 5,
                    textPaint);
        }
        spaceq = (right_q - left_q - textW) / 5;
        for (int i = 1; i < 7; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_q, textHeight + textHeight / 5,
                    textPaint);

            left_q += txWidth + spaceq;

        }
        spaceh = (right_h - left_h - textW) / 5;
        for (int i = 7; i < 13; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_h, textHeight + textHeight / 5,
                    textPaint);

            left_h += txWidth + spaceh;

        }

    }

    //EAN_8条码下方
    protected void textalignEan_8Center(float left, float top, float textHeight, String content, Paint textPaint, Canvas canvas) {
        char[] arr = content.toCharArray();

        //获取总的长度
        float txWidth = getContentWhidth(textPaint, "5");//文字的宽度
        float w;// = this.width;
        float left_q;// = left + w / 20;
        float right_q;// = w / 2 - w / 30;
        float textW;// = txWidth * 4;

        float spaceq = 0;//前面字符空隙 总宽度-字符串宽度
        float left_h;// = w / 2 + w / 30;
        float right_h;// = w - w / 20;


        float spaceh = 0;//后面字符空隙 总宽度-字符串宽度
        if (rate == 90 || rate == 270) {
            w = this.height / compressionRatio;
            left_q = left + w / 20;
            right_q = w / 2 - w / 30;
            textW = txWidth * 4;
            left_h = w / 2 + w / 30;
            right_h = w - w / 20;
        } else {
            w = this.width / compressionRatio;
            left_q = left + w / 20;
            right_q = w / 2 - w / 30;
            textW = txWidth * 4;


            left_h = w / 2 + w / 30;
            right_h = w - w / 20;

        }
        Paint p = new Paint();
        p.setColor(Color.WHITE);
        canvas.drawRect(left_q, top + textHeight / 2, right_q, top - textHeight / 2, p);
        canvas.drawRect(left_h, top + textHeight / 2, right_h, top - textHeight / 2, p);

        spaceq = (right_q - left_q - textW) / 3;
        for (int i = 0; i < 4; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_q, top + textHeight / 5,
                    textPaint);

            left_q += txWidth + spaceq;

        }
        spaceh = (right_h - left_h - textW) / 3;
        for (int i = 4; i < 8; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_h, top + textHeight / 5,
                    textPaint);

            left_h += txWidth + spaceh;

        }

    }

    //EAN_8条码上方
    protected void textalignEan_8CenterXia(float left, float top, float textHeight, String content, Paint
            textPaint, Canvas canvas) {
        char[] arr = content.toCharArray();

        //获取总的长度
        float txWidth = getContentWhidth(textPaint, "5");//文字的宽度
        float w;
        float right_q;// = w / 2 - w / 30;
        float left_q;// = left + w / 20;
        float textW;// = txWidth * 4;

        float spaceq = 0;//前面字符空隙 总宽度-字符串宽度
        float right_h;// = w - w / 20;
        float left_h;// = w / 2 + w / 30;
        // float textW_h= txWidth*6;
        float spaceh = 0;//后面字符空隙 总宽度-字符串宽度
        if (rate == 90 || rate == 270) {
            w = this.height;
            right_q = w / 2 - w / 30;
            left_q = left + w / 20;
            textW = txWidth * 4;


            right_h = w - w / 20;
            left_h = w / 2 + w / 30;
        } else {
            w = this.width;
            right_q = w / 2 - w / 30;
            left_q = left + w / 20;
            textW = txWidth * 4;


            right_h = w - w / 20;
            left_h = w / 2 + w / 30;


        }
        Paint p = new Paint();
        p.setColor(Color.WHITE);
        canvas.drawRect(left_q, textHeight / 2, right_q, textHeight * 3 / 2, p);
        canvas.drawRect(left_h, textHeight / 2, right_h, textHeight * 3 / 2, p);

        spaceq = (right_q - left_q - textW) / 3;
        for (int i = 0; i < 4; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_q, textHeight + textHeight / 5,
                    textPaint);

            left_q += txWidth + spaceq;

        }
        spaceh = (right_h - left_h - textW) / 3;
        for (int i = 4; i < 8; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_h, textHeight + textHeight / 5,
                    textPaint);

            left_h += txWidth + spaceh;

        }

    }

    //Upc_A条码上方
    protected void textalignUpc_ACenterXia(float left, float top, float textHeight, String content, Paint
            textPaint, Canvas canvas) {
        char[] arr = content.toCharArray();

        //获取总的长度
        float txWidth = getContentWhidth(textPaint, "5");//文字的宽度
        float w;// = this.width;
        float left_q;// = left + txWidth + w / 30;
        float right_q;// = w / 2 - w / 50;
        float textW;// = txWidth * 5;

        float spaceq = 0;//前面字符空隙 总宽度-字符串宽度
        float left_h;// = w / 2 + w / 50;
        float right_h;// = (w - txWidth) - (w - txWidth) / 30;
        float spaceh = 0;//后面字符空隙 总宽度-字符串宽度
        if (rate == 90 || rate == 270) {
            w = this.height / compressionRatio;
            left_q = left + txWidth + w / 30;
            right_q = w / 2 - w / 50;
            textW = txWidth * 5;
            left_h = w / 2 + w / 50;
            right_h = (w - txWidth) - (w - txWidth) / 30;
        } else {
            w = this.width / compressionRatio;
            left_q = left + txWidth + w / 30;
            right_q = w / 2 - w / 50;
            textW = txWidth * 5;


            left_h = w / 2 + w / 50;
            right_h = (w - txWidth) - (w - txWidth) / 30;


        }
        Paint p = new Paint();
        p.setColor(Color.WHITE);
        canvas.drawRect(left_q, textHeight / 2, right_q, textHeight * 3 / 2, p);
        canvas.drawRect(left_h, textHeight / 2, right_h, textHeight * 3 / 2, p);
        for (int i = 0; i < 1; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left, textHeight + textHeight / 2,
                    textPaint);


        }

        spaceq = (right_q - left_q - textW) / 4;
        for (int i = 1; i < 6; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_q, textHeight + textHeight / 5,
                    textPaint);

            left_q += txWidth + spaceq;

        }
        spaceh = (right_h - left_h - textW) / 4;
        for (int i = 6; i < 11; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_h, textHeight + textHeight / 5,
                    textPaint);

            left_h += txWidth + spaceh;

        }
        for (int i = 11; i < 12; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left + w - txWidth, textHeight + textHeight / 2,
                    textPaint);
        }

    }

    //Upc_A条码下方
    protected void textalignUpc_ACenter(float left, float top, float textHeight, String content, Paint
            textPaint, Canvas canvas) {
        char[] arr = content.toCharArray();

        //获取总的长度
        float txWidth = getContentWhidth(textPaint, "5");//文字的宽度
        float w = this.width;
        float left_q;// = left + txWidth + w / 30;
        float right_q;// = w / 2 - w / 50;
        float textW;// = txWidth * 5;

        float spaceq = 0;//前面字符空隙 总宽度-字符串宽度

        float left_h;// = w / 2 + w / 50;
        float right_h;// = (w - txWidth) - (w - txWidth) / 30;


        float spaceh = 0;//后面字符空隙 总宽度-字符串宽度
        if (rate == 90 || rate == 270) {
            w = this.height / compressionRatio;
            left_q = left + txWidth + w / 30;
            right_q = w / 2 - w / 50;
            textW = txWidth * 5;

            left_h = w / 2 + w / 50;
            right_h = (w - txWidth) - (w - txWidth) / 30;
        } else {
            w = this.width / compressionRatio;
            left_q = left + txWidth + w / 30;
            right_q = w / 2 - w / 50;
            textW = txWidth * 5;

            left_h = w / 2 + w / 50;
            right_h = (w - txWidth) - (w - txWidth) / 30;


        }
        Paint p = new Paint();
        p.setColor(Color.WHITE);
        canvas.drawRect(left_q, top + textHeight / 2, right_q, top - textHeight / 2, p);
        canvas.drawRect(left_h, top + textHeight / 2, right_h, top - textHeight / 2, p);
        for (int i = 0; i < 1; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left, top - textHeight / 30,
                    textPaint);


        }
        spaceq = (right_q - left_q - textW) / 4;
        for (int i = 1; i < 6; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_q, top + textHeight / 5,
                    textPaint);

            left_q += txWidth + spaceq;

        }
        spaceh = (right_h - left_h - textW) / 4;
        for (int i = 6; i < 11; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left_h, top + textHeight / 5,
                    textPaint);

            left_h += txWidth + spaceh;

        }
        for (int i = 11; i < 12; i++) {
            String vString = String.valueOf(arr[i]);
            canvas.drawText(vString, left + w - txWidth, top - textHeight / 30,
                    textPaint);
        }

    }

    /**
     * 计算文本宽度
     * @param textPaint 画笔
     * @param content   文本内容
     * @return
     */
    public float getContentWhidth(Paint textPaint, String content) {
        if (textPaint == null || TextUtils.isEmpty(content)) {
            return 0;
        }
        if(isArab || StringUtils.textContainsKhmer(content)){
            return textPaint.measureText(content);
        }else {
            float mun = 0;
            char[] chars = content.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                mun += textPaint.measureText(String.valueOf(chars[i]));
            }
            return mun;
        }
    }

    //非双击普通点击两次操作（表格选择单元格）
    public void selecting(float x, float y) {
    }

    //判断是否非双击普通点击两次
    public void selecting() {
    }

    //移动则取消非双击普通点击两次（表格取消单元格操作）
    public void selecting(boolean Boolean) {
    }
}
